package c_002;

/**
 * 分析下这个程序的输出
 */
public class T02 implements Runnable {

    private /*volatile*/ int count = 100;

    //此处synchronized可以解决T01问题,那么加了synchronized还需要加volatile吗
    //不需要,synchronized既保证了原子性又保证了可见性
    public synchronized void run(){
        count--;
        System.out.println(Thread.currentThread().getName() + " count = " + count);
    }

    public static void main(String[] args) {
        T02 t = new T02();
        for(int i = 0; i < 5; i++){
            new Thread(t, "THREAD" + i).start();
        }
    }
}
